package com.wdc.patterns.singleton.demo6;

import java.io.*;

public class Client {
    public static void main(String[] args) throws Exception {
//        writeObject2File();
        readObjectFile();
        readObjectFile();
    }

    public static void readObjectFile() throws Exception {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("W:\\a.txt"));
        Singleton singleton = (Singleton) ois.readObject();
        System.out.println(singleton);
    }
    public static void writeObject2File() throws Exception {
        Singleton instance = Singleton.getInstance();
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("W:\\a.txt"));
        oos.writeObject(instance);
        //释放资源
        oos.close();

    }
}
